#!/bin/python3
# -*- coding: utf-8 -*-


class ContactList(list):
    def search(self, name):

        matching_contacts = []
        for contact in self:
            if name in contact.name:
                matching_contacts.append(contact)
        return matching_contacts


class Contact:
    all_contacts = ContactList()

    def __init__(self, name, email):
        self.name = name
        self.email = email
        self.all_contacts.append(self)


class LongNameDict(dict):
    def longest_key(self):
        longest = None
        for key in self:
            if not longest or len(key) > len(longest):
                longest = key
        return longest


# 钻石型继承的问题 引用父类的方法重复的问题
class BaseClass:
    num_base_calls = 0

    def call_me(self):
        print('calling base class')
        self.num_base_calls += 1


class LeftSubclass(BaseClass):
    num_left_class = 0

    def call_me(self):
        super().call_me()
        print('calling left subclass')
        self.num_base_calls += 1


class RightSubclass(BaseClass):
    num_right_class = 0

    def call_me(self):
        super().call_me()
        print('calling right subclass')
        self.num_right_class += 1


class Subclass(LeftSubclass, RightSubclass):
    num_sub_class = 0

    def call_me(self):
        super().call_me()
        print('calling subclass')
        self.num_sub_class += 1
